$(function () {
    $(".ordinary").click(function () {
        $(".quick").removeClass("active");
        $(this).addClass("active");
        $(".input_password").show();
        $(".input_checkcode").hide();
    });
    $(".quick").click(function () {
        $(".ordinary").removeClass("active");
        $(this).addClass("active");
        $(".input_password").hide();
        $(".input_checkcode").show();
    });

    $("#btnRegist").click(function () {
        var mobile = $("#mobile").val();
        var imageCaptcha = $("#imageCaptcha").val();
        var temp = $(".input_checkcode").is(":hidden");//是否隐藏
        var temp1 = $(".input_password").is(":hidden");
        var pwd = $("#pwd").val();
        var checkcode = $("#checkcode").val();
        if (mobile === "") {
            alert("手机号码不能为空！");
            return;
        }
        else {
            if (!isMoible(mobile)) {
                alert("手机号码格式不正确！");
                return;
            }
        }

        if (imageCaptcha === "") {
            alert("请填写图片验证码!");
            return;
        }
        if (temp) {
            if (pwd === "") {
                alert("密码不能为空！");
                return;
            }
            $.ajax({
                type: "post",
                url: "/Manage/checklogin.do",
                timeout: 1000,
                data: {mobile: mobile, password: pwd, imageCaptcha: imageCaptcha},
                dataType: "json",
                cache: false,
                success: function (data) {
                    if (data.success) {
                        alert("登录成功");
                        if (data.model === null) {
                            location.href = "/Manage/subinfo.do";
                        } else {
                            if (data.model.enable === 1) {
                                location.href = "/Manage/index.do";
                            } else if (data.model.enable === 0) {
                                location.href = "/Manage/subedinfo.do";
                            } else {
                                location.href = "/Manage/subinfo.do";
                            }
                        }

                    } else {
                        alert(data.message);
                    }
                }
            });
        } else {
            if (checkcode === "") {
                alert("请填写手机验证码!");
                return;
            }
            $.ajax({
                type: "post",
                url: "/Manage/quicklogin.do",
                timeout: 1000,
                data: {mobile: mobile, checkcode: checkcode, imageCaptcha: imageCaptcha},
                dataType: "json",
                cache: false,
                success: function (data) {
                    if (data.success) {
                        alert("登录成功");
                        if (data.model === null) {
                            location.href = "/Manage/subinfo.do";
                        } else {
                            if (data.model.shop.enable === 1) {
                                location.href = "/Manage/index.do";
                            } else if (data.model.shop.enable === 0) {
                                location.href = "/Manage/subedinfo.do";
                            } else {
                                location.href = "/Manage/subinfo.do";
                            }
                        }
                    } else {
                        alert("登录失败");
                    }
                }
            });
        }
    });
});
var InterValObj; //timer变量，控制时间
var count = 120; //间隔函数，1秒执行
var curCount;//当前剩余秒数
function sendMessage() {
    var strmobile = $("#mobile").val();
    var imageCaptcha = $("#imageCaptcha").val();

    if (strmobile === "") {
        alert("手机号码不能为空！");
        return;
    }
    else {
        if (!isMoible(strmobile)) {
            alert("手机号码格式不正确！");
            return;
        }
    }
    if (imageCaptcha === "") {
        alert("请填写图片验证码!");
        return;
    }
    //向后台发送处理数据       
    $.ajax({
        type: "post",
        url: "/Manage/sendSms.do",
        timeout: 1000,
        data: {mobile: $.trim($("#mobile").val()), imageCaptcha: imageCaptcha},
        dataType: "json",
        cache: false,
        success: function (data) {
            if (data.success) {
                curCount = count;
                //设置button效果，开始计时               
                $("#btnSendCode").prop("disabled", true);
                $("#btnSendCode").html(curCount + "秒");
                InterValObj = window.setInterval(SetRemainTime, 1000);
                //启动计时器，1秒执行一次
            } else {
                alert(data.message);
            }
        }
    });

}
//timer处理函数
function SetRemainTime() {
    if (curCount === 0) {
        window.clearInterval(InterValObj);
        //停止计时器               
        $("#btnSendCode").prop("disabled", false);
        //启用按钮                
        $("#btnSendCode").html("重新发送");
    }
    else {
        curCount--;
        $("#btnSendCode").html(curCount + "秒");
    }
}
function isMoible(mobile) {
    if (!(/^1[3|4|5|7|8][0-9]\d{8}$/.test(mobile))) {
        return false;
    }
    return true;
}
function reImg() {
    var img = document.getElementById("Img");
    img.src = "/Manage/captcha.do?" + Math.random();
}


